package cn.knight.mq.easy;



import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
* @Description: 消费者
* @Author: Winnie
* @Version: 1.0
* @Date:  2022/7/25 12:52
  */
public class Producer {

    public static void main(String[] args) throws Exception {
        // 创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("snyc_hello_group");

        // 连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");

        // 启动mq
        producer.start();

        // 编写消息
        Message message = new Message("hello_topic", "hello_tags", "蒙多想去哪就去哪".getBytes(StandardCharsets.UTF_8));

        // 发送消息
        SendResult result = producer.send(message);

        System.out.println(result);

        // 关闭连接
        producer.shutdown();

    }
}
